package com.heart.cn.service.deal;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.heart.cn.model.Cmder;
import com.heart.cn.model.HeartbeatEntity;
import com.heart.cn.service.HeartbeatLinstener;

/**
 * 心跳处理实现
 * @author wangzh
 * @date 2019年8月1日 下午7:00:47
 */
public class HeartbeatHandlerImpl implements HeartbeatHandler {
	
	private static Logger log= LoggerFactory.getLogger(HeartbeatHandlerImpl.class);

    public Cmder sendHeartBeat(HeartbeatEntity info) {

        HeartbeatLinstener linstener = HeartbeatLinstener.getInstance();

        // 添加节点

        if (!linstener.checkNodeValid(info.getNodeID())) {
            linstener.registerNode(info.getNodeID(), info);
        }

 

        // 其他操作

       Cmder cmder = new Cmder();
       cmder.setNodeID(info.getNodeID());


        Map<String, Object> nodes = linstener.getNodes();

        for (String key: nodes.keySet()) {
            log.info("key："+key + " value:" + nodes.get(key));
        }

        return cmder;

    }


}
